/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TestModulePanel.java
 *
 * Created on 2009-12-10, 07:32:11
 */
package pl.edu.wat.erp.client.testmodule;

import java.util.logging.Level;
import java.util.logging.Logger;
import wat.ziszcommon.clientgui.FunctionBase;
import wat.ziszcommon.clientgui.MyJTree;
import wat.ziszcommon.remote.ClassProvider;
import wat.ziszcommon.remote.RemoteModuleFactory;

/**
 *
 * @author Krzysiek
 */
public class TestModulePanel extends FunctionBase<TestModulePanel.TestModule> {

    public interface TestModule extends FunctionBase.BaseServStub {

        public String sayHello(String name);

        public int add(int value1, int value2);
    }

    /** Creates new form TestModulePanel */
    public TestModulePanel(String name, MyJTree tree, TestModule stub) {
        super(name, tree, stub);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nameLabel = new javax.swing.JLabel();
        name = new javax.swing.JTextField();
        sayHelloButton = new javax.swing.JButton();
        sayHelloResponseLabel = new javax.swing.JLabel();
        sayHelloResponse = new javax.swing.JTextField();
        value1Label = new javax.swing.JLabel();
        value1 = new javax.swing.JTextField();
        value2Label = new javax.swing.JLabel();
        value2 = new javax.swing.JTextField();
        addButton = new javax.swing.JButton();
        addResponseLabel = new javax.swing.JLabel();
        addResponse = new javax.swing.JTextField();

        nameLabel.setText("Name:");

        sayHelloButton.setText("witaj!");
        sayHelloButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sayHelloButtonActionPerformed(evt);
            }
        });

        sayHelloResponseLabel.setText("Response:");

        sayHelloResponse.setEnabled(false);

        value1Label.setText("Value 1:");

        value2Label.setText("Value 2:");

        addButton.setText("add");
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addButtonActionPerformed(evt);
            }
        });

        addResponseLabel.setText("Response:");

        addResponse.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sayHelloResponseLabel)
                            .addComponent(nameLabel)
                            .addComponent(value1Label))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sayHelloResponse, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                            .addComponent(name, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(value1, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(value2Label)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(value2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(addResponseLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(addResponse, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(addButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(sayHelloButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {value1, value2});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameLabel)
                    .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sayHelloButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sayHelloResponseLabel)
                    .addComponent(sayHelloResponse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(value1Label)
                    .addComponent(value1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(value2Label)
                    .addComponent(value2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(addButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addResponse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(addResponseLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void sayHelloButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sayHelloButtonActionPerformed
        sayHelloResponse.setText(getServerObj().sayHello(name.getText()));
    }//GEN-LAST:event_sayHelloButtonActionPerformed

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
        try {
            Class c = Class.forName("pl.edu.wat.erp.client.testmodule.TestClass");
            Object obj = c.newInstance();
            if(obj instanceof TestInterface) {
                TestInterface testInterface = (TestInterface) obj;
                addResponse.setText(testInterface.getString());
            }
        } catch (InstantiationException ex) {
            Logger.getLogger(TestModulePanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(TestModulePanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(TestModulePanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        //addResponse.setText(Integer.toString(getServerObj().add(Integer.parseInt(value1.getText()), Integer.parseInt(value2.getText()))));
    }//GEN-LAST:event_addButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addButton;
    private javax.swing.JTextField addResponse;
    private javax.swing.JLabel addResponseLabel;
    private javax.swing.JTextField name;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JButton sayHelloButton;
    private javax.swing.JTextField sayHelloResponse;
    private javax.swing.JLabel sayHelloResponseLabel;
    private javax.swing.JTextField value1;
    private javax.swing.JLabel value1Label;
    private javax.swing.JTextField value2;
    private javax.swing.JLabel value2Label;
    // End of variables declaration//GEN-END:variables

    @Override
    public void initClient() {
        System.out.println("TestModule");
    }
}
